#include <avr/interrupt.h>

#include "extirq.h"


static uint16_t ticks;


ISR(INT0_vect) {
    ticks++;
}


void extirq_init() {
    /* 
     * Triggering is as follows:
     *  ISC00   ISC01
     *      0       0   low level
     *      0       1   any logical change triggers
     *      1       0   falling edge
     *      1       1   rising edge
     */
    EICRA = _BV(ISC01); /* Trigger on falling edge */

    EIMSK = _BV(INT0); /* Enable INT0 */

    ticks = 0;
}


uint16_t extirq_ticks()
{
    return ticks;
}


